#ifndef xpack_test_algo_remove
#define xpack_test_algo_remove
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::test_algo_remove::inc
#include"test/helper.hpp" // 需要放第一
#include"algo/remove.hpp"
#include"concurrency/thread_self.hpp"
#include"define/nullref.hpp"
#include"utils/array.hpp"
#include"utils/memory.hpp"
#include"utils/shared.hpp"
#pragma pop_macro("xuser")

namespace mixc::test_algo_remove{
    xtest("remove"){
        auto a = inc::make_array(0u, 1u, 2u);
        auto b = a;
        auto l = uxx{};

        l = inc::remove(b, 0);
        xassert_eq(a->length - 1, l);
        xassert_eq(a[1], b[0]);
        xassert_eq(a[2], b[1]);

        b = a;
        l = inc::remove(b, 1);
        xassert_eq(a->length - 1, l);
        xassert_eq(a[0], b[0]);
        xassert_eq(a[2], b[1]);

        b = a;
        l = inc::remove(b, 2);
        xassert_eq(a->length - 1, l);
        xassert_eq(a[0], b[0]);
        xassert_eq(a[1], b[1]);

        b = a;
        l = inc::remove(b, -1);
        xassert_eq(a->length - 1, l);
        xassert_eq(a[0], b[0]);
        xassert_eq(a[1], b[1]);

        b = a;
        l = inc::remove(b, cc{0,1});
        xassert_eq(a->length - 2, l);
        xassert_eq(a[2], b[0]);

        b = a;
        l = inc::remove(b, co{0});
        xassert_eq(0u, l);

        auto used = inc::memory::used_bytes();
        auto dummy = inc::memory::alloc<u32>();
        {
            using item_t = inc::shared<u32>;

            inc::array<item_t, 3> a { 
                inc::init_by{ 1u },
                inc::init_by{ 2u },
                inc::init_by{ 3u }
            };

            inc::remove(a, 0);
            xassert_eq(2u, *a[0]);
            xassert_eq(3u, *a[1]);
            xassert_eq(nullptr, a[2]);
        }

        inc::thread_self::gc_sync();
        inc::thread_self::sleep(32);
        inc::memory::free<u32>(dummy); // gc 使用的是推送模式，只有当前线程调用 free 接口才能触发推送处理
        xassert_eq(used, inc::memory::used_bytes());
    };
}

#endif
